package com.example.arithmeticleetcode.leetcode.october;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-27 09:10
 **/
public class Demo16 {

    public static void main(String[] args) {
        int[] arr1 = {4,2,1,3};
        int[] arr2 = {1,3,6,10,15};
        int[] arr3 = {3,8,-10,23,19,-4,-14,27};
        System.out.println(minimumAbsDifference(arr1));
        System.out.println(minimumAbsDifference(arr2));
        System.out.println(minimumAbsDifference(arr3));
    }

    public static List<List<Integer>> minimumAbsDifference(int[] arr) {
        Arrays.sort(arr);
        int min = Integer.MAX_VALUE;
        for (int i = 1, len = arr.length; i < len; i++) {
            int differenceValue = arr[i] - arr[i - 1];
            if (min > differenceValue) {
                min = differenceValue;
            }
        }
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 1, len = arr.length; i < len; i++) {
            int differenceValue = arr[i] - arr[i - 1];
            if (min == differenceValue) {
                list.add(Arrays.asList(arr[i - 1], arr[i]));
            }
        }
        return list;
    }
}
